package com.example.myworkers.controller;

import com.example.myworkers.model.Car;
import com.example.myworkers.service.CarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


/**
 * 编写者：门硕然
 */
@Api(tags = "Car")
@RestController
@RequestMapping("/car")
public class CarController {

    @Autowired
    private CarService carService;


    @ApiOperation(value = "添加方法")
    @PostMapping("/addCar")
    @CrossOrigin
    public int addCar(@RequestBody Car car){
        System.out.println("进入添加信息接口");
        return carService.insertCar(car);
    }


    @ApiOperation(value = "删除方法")
    @GetMapping("/deleteCar")
    @CrossOrigin
    public int deleteCar(int id){
        System.out.println("进入删除接口");
        int returnValue=0;
        if (id!=0){
            Car car=new Car();
            car.setCarid(id);
            returnValue=carService.deleteCar(car);
        }
        return returnValue;
    }

    @ApiOperation(value = "修改方法")
    @PostMapping("/editCar")
    @CrossOrigin
    public int editCar(@RequestBody Car car){
        System.out.println("进入修改接口");
        return carService.updateCar(car);
    }

    @ApiOperation(value = "查询方法-单个")
    @GetMapping("/getOne")
    @CrossOrigin
    public Car getCar(int id){
        System.out.println("进入单条查询接口");
        Car car=new Car();
        if (id!=0){
            Car car1=new Car();
            car1.setCarid(id);
            car=carService.selectCar(car1);
            System.out.println("返回的数据集合为"+car.getLicense());
        }
        return car;
    }


    @ApiOperation(value = "查询方法")
    @GetMapping("/getAll")
    @CrossOrigin
    public List<Car> getAllCar(String license){
        System.out.println("进入查询接口");
        return carService.selectAllCar(license);
    }






}













